﻿using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace CPPEI.Coolzon.Designer.Views
{
    public class GetLatestVersionCommand
    {
        public static void Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (UIContext.Current.CurrentSelectedNode != null)
            {
                GetLatestVersionThread.Start(UIContext.Current.CurrentSolution.ID, ReportProgress, Completed);
            }
        }
        public static void CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (UIContext.Current.CurrentSelectedNode != null && UIContext.Current.CurrentSelectedNode.NodeStatus != NodeStatus.Delete)
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }

        public static void ReportProgress(Guid id, string name, int current, int total)
        {

        }

        public static void Completed(bool HasError, int successed, int total)
        {
            if (HasError)
            {
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    CustomMessageBox.ShowError("获取最新失败");
                });
                return;
            }
            OpenSolutionThread.Start(UIContext.Current.CurrentSolution.ID);
        }
    }
}
